package com.uit.se6.mydiary.data;

import android.content.Context;
import android.content.SharedPreferences;

public class MySharedPreference {

	public static String preName = "MyData";
	static SharedPreferences sharedPreferences = null;
	static SharedPreferences.Editor editor;

	public MySharedPreference(Context context) {
		if (sharedPreferences == null) {
			sharedPreferences = context.getSharedPreferences(preName, 0);
			editor = sharedPreferences.edit();
		}
	}

	public void updateString(String key, String value) {
		editor.putString(key, value);
		editor.apply();
	}

	public String getString(String key, String defValue) {
		return sharedPreferences.getString(key, defValue);
	}

	public void updateBoolean(String key, boolean value) {
		editor.putBoolean(key, value);
		editor.apply();
	}

	public boolean getBoolean(String key, boolean defaultValue) {
		return sharedPreferences.getBoolean(key, defaultValue);
	}

	public void updateInt(String key, int value) {
		editor.putInt(key, value);
		editor.apply();
	}

	public int getInt(String key, int defValue) {
		return sharedPreferences.getInt(key, defValue);
	}
	
	public static String KEY_NOTE_START_WITH  =  "str_note_start_with";
}